<?php
App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class ServicesController extends AppController {

/**
 * This controller does not use a model
 *
 * @var array
 */
	public $uses = array('Services');

	public function index(){
		$services=$this->Services->find('all',array('conditions'=>array('Services.is_delete ='=>0)));
		$this->set("data",$services);		
	}

	public function add(){
		if(!empty($this->data)){
			//var_dump($this->data);
			$this->request->data['amount']=1;
			$this->request->data['total_price']=$this->data['unit_price'];
			$this->Services->set($this->data);
			if($this->Services->validates()){
				if($this->Services->save($this->data)){
					$this->redirect('/services');
				}
			}
			else{
				$errors = $this->Member->validationErrors;
				var_dump($errors);
				//$this->layout=false;
				//$this->render(false);	
				//$this->Session->setFlash(__("Error", true), 'flash', array('class' => 'alert alert-error'));
			}	
			$this->layout=false;
			$this->render(false);	
		}
	}

	public function edit($id){
		if (!empty($this->data))
		{
			$this->request->data['amount']=1;
			$this->request->data['total_price']=$this->data['unit_price'];			
    	$this->Services->id = $id;        
    	if ($this->Services->save($this->data)) 
    	{
    	  //$this->Session->setFlash('Socio Actualizado.', 'flash', array('class' => 'thrill'));
        $this->redirect('/services');
      }
    }
    else {
        $this->request->data = $this->Services->findById($id);
    }

		$this->render("add");
	}

	public function delete($id){
		$this->layout=false;
		$this->render(false);
		$this->Member->delete($id);
		$this->redirect('/services');
	}
}
